<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<input type="text" />
		<input type="text" />
		<input type="text" />
	</body>
</html>

<script type="text/javascript">
	// 给input绑定获取焦点和失去焦点事件,获得焦点时设置背景颜色为红色
	var inputs = document.querySelectorAll('input');
	for (var i=0;i<inputs.length;i++) {
		inputs[i].onfocus = function() {
			console.log(this);
			this.style.background = 'red'; 
		}
	}
	
	for (var i=0;i<inputs.length;i++) {
		inputs[i].onblur = function() {
			console.log(this);
			this.style.background = ''; 
		}
	}
	
	
	
</script>